/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aal.model;

import com.aal.business.CustomerManagementLocal;
import com.aal.entity.Customer;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author quy
 */
public class CustomerManagement {
    CustomerManagementLocal customerManagement = lookupCustomerManagementLocal();
    private String username;
    private String password;
    private int customergroupId;
    private String firstname;
    private String lastname;
    private String email;
    private String phone;
    private String billingaddress;

    public int getCustomergroupId() {
        return customergroupId;
    }

    public void setCustomergroupId(int customergroupId) {
        this.customergroupId = customergroupId;
    }
    
    public String getBillingaddress() {
        return billingaddress;
    }

    public void setBillingaddress(String billingaddress) {
        this.billingaddress = billingaddress;
    }
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getUsername() {
        return username;
    }

    public Customer getCustomer() {
        return customerManagement.getCustomer(username);
    }
    
    public void setUsername(String username) {
        this.username = username;
    }
    public boolean getCreateuser(){
        return customerManagement.createCustomer(username, password, customergroupId, 
                firstname, lastname, email, phone, billingaddress);
    }
    public boolean getEdituser(){
        return customerManagement.editCustomer(username, password, customergroupId, 
                firstname, lastname, email, phone, billingaddress);
    }
    public List<Customer> getSearchbyname(){
        return customerManagement.searchbyName(username);
    }
    public double getDiscountCustomerGroup(){
        return customerManagement.getDiscoutCustomerGroup(customergroupId);
    }
    public boolean getLoginOk(){
        return customerManagement.loginOk(username, password);
    }
    private CustomerManagementLocal lookupCustomerManagementLocal() {
        try {
            Context c = new InitialContext();
            return (CustomerManagementLocal) c.lookup("java:global/AAL/AAL-ejb/CustomerManagement!com.aal.business.CustomerManagementLocal");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
}
